Skip to content

judge: fix cac load#1158

Merged
undefined-moe merged 1 commit into
hydro-dev:masterfrom
renbaoshuo:fix/judge-cac-load
May 8, 2026
Merged

judge: fix cac load#1158
undefined-moe merged 1 commit into
hydro-dev:masterfrom
renbaoshuo:fix/judge-cac-load

Conversation

@renbaoshuo
Copy link
Copy Markdown
Contributor

@renbaoshuo renbaoshuo commented May 8, 2026

Resolves #1154. Fixes 7bb29b8.


image

Summary by CodeRabbit

  • Bug Fixes
    • Fixed command-line argument parsing to ensure CLI commands are properly recognized and executed.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

Walkthrough

This pull request fixes a single-line bug in the hydrojudge CLI entry point. The initialization chain for the cac argument parser was incorrect—calling the module as a function before accessing the .cac() method. The fix removes the erroneous function invocation, changing require('cac')().cac().parse() to require('cac').cac().parse(). This restores proper behavior and resolves ESM compatibility issues on Node 22. The command routing logic (cache, terminal, or daemon modes) is unaffected.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'judge: fix cac load' directly addresses the main change—fixing the cac module loading issue in hydrojudge CLI.
Linked Issues check ✅ Passed The PR correctly fixes the ESM compatibility issue with cac on Node 22 by correcting require('cac')() to require('cac'), resolving issue #1154.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the cac module loading in hydrojudge.js with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/hydrojudge/bin/hydrojudge.js`:
- Line 3: The current call uses require('cac').cac() which fails with cac 7
because the module exports the caf function directly; update the code that sets
argv (the expression using require('cac').cac()) to call the default export
instead: either change to require('cac')().parse() for CommonJS on Node
>=20.19.0, or migrate the file to ESM and import the default (import cac from
'cac'; const argv = cac().parse()) so argv is created from a proper cac() call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d1e2ec2-92cb-475a-a054-fa5e1a028af8

📥 Commits

Reviewing files that changed from the base of the PR and between ca2fb94 and 98d9665.

📒 Files selected for processing (1)
  • packages/hydrojudge/bin/hydrojudge.js

#!/usr/bin/env node

const argv = require('cac')().cac().parse();
const argv = require('cac').cac().parse();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

Does cac 7.0.0 npm package export a named cac function accessible via require('cac').cac in CommonJS?

💡 Result:

No, the cac 7.0.0 npm package does not export a named cac function accessible via require('cac').cac in CommonJS. In version 7.0.0, CAC removed its CJS build and is now ESM-only, with "type": "module" in package.json and exports pointing to./dist/index.js.[1][2] The official release notes explicitly state: "Remove CJS build. CAC is now ESM-only. If you rely on require(), either migrate to ESM imports or upgrade to Node.js ≥ 20.19.0, which supports require() for ES modules natively."[1] While Node.js >=20.19.0 allows require on ESM modules (returning the default export), it provides the default export directly as require('cac'), not as a named property.cac. All documentation and examples use import cac from 'cac' or const cli = cac(), confirming cac is the default export, with no evidence of named exports like { cac }.[3][4][5]

Citations:


The fix require('cac').cac() is incorrect for cac 7.0.0.

cac 7.0.0 removed its CJS build and is now ESM-only. According to the official release notes, require('cac') on Node.js ≥20.19.0 returns the default export directly—the cac function itself. There is no named cac property; accessing require('cac').cac will fail.

For CommonJS with Node ≥20.19.0, use:

const argv = require('cac')().parse();

For ESM (recommended), migrate to:

import cac from 'cac';
const argv = cac().parse();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/hydrojudge/bin/hydrojudge.js` at line 3, The current call uses
require('cac').cac() which fails with cac 7 because the module exports the caf
function directly; update the code that sets argv (the expression using
require('cac').cac()) to call the default export instead: either change to
require('cac')().parse() for CommonJS on Node >=20.19.0, or migrate the file to
ESM and import the default (import cac from 'cac'; const argv = cac().parse())
so argv is created from a proper cac() call.

@undefined-moe undefined-moe merged commit bbcaa61 into hydro-dev:master May 8, 2026
6 checks passed
@renbaoshuo renbaoshuo deleted the fix/judge-cac-load branch May 8, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants